<?php

use yii\helpers\Url;
use yii\helpers\Html;
use website\helpers\Render;
use common\models\Design;
use common\models\Recruit;

$this->addCrumbs('招聘信息', 'search/recruit');
$this->title = Render::interceptHtml($recruit->title, 16);
?>
<style>
    #user-photo {padding:20px 0;}
    #user-photo .imager {width:200px;height:200px;margin:0 40px;border-radius:200px;overflow:hidden;}
    #user-photo .imager img {width:100%;height:100%;border:none;}
    #user-photo .username {margin-top:10px;line-height:30px;font-size:16px;text-align:center;}
</style>

<div class="contenter">

    <?= $this->render('/layouts/break-crumbs') ?>

    <div class="clear mt-20px pb-20px">
        <div class="box-shadow w-900px pt-10px pb-10px fl">
            <div class="pd-20px">
                <h3 class="fs-18px"><?= $recruit->title ?><span class="fr cl-red"><?= Recruit::$budgetSelector[$recruit->budget]['title'] ?></span></h3>
                <div class="cl-gray mt-20px pb-20px bb">发布日期：<?= date('Y-m-d', $recruit->created_at) ?></div>
                <div class="mt-20px">
                    <span class="inline-block w-180px">类目：<span class="categories"><?= $recruit->categories ?></span></span>
                    <span class="inline-block w-280px">类型：<span class="models"><?= $recruit->models ?></span></span>
                    <span class="inline-block w-280px">风格：<span class="styles"><?= $recruit->styles ?></span></span>
                </div>
                <div class="mt-40px">
                    <h3 class="fs-16px"><i class="icon-file"></i> 详细需求</h3>
                    <div class="clear lh-35px"><?= $recruit->remark ?></div>
                </div>
                <div class="mt-20px">
                    <?php if($applicant) { ?>
                        <span class="flyer-status green mr-20px">已投递</span> <span class="cl-gray">投递时间：<?= date('Y-m-d H:i:s', $applicant->created_at) ?></span>
                    <?php } else { ?>
                        <button class="flyer-button normal border-round" id="delivery-button">投递简历</button>
                    <?php } ?>
                </div>
            </div>
        </div>
        <div class="w-280px fr">
            <div class="box-shadow mb-20px" id="user-photo">
                <div class="imager"><a href="<?= Url::to('@web/user/photo') ?>"><img src="<?= Render::upload(\Yii::$app->getUser()->photo) ?>"></a></div>
                <div class="username">
                    <p><?= \Yii::$app->getUser()->nickname ?></p>
                    <p class="mt-10px">
                        <a class="flyer-button normal border-round narrow" href="<?= Url::to('@web/designer/index') ?>">进入工作台</a>
                        <a class="flyer-button normal border-round narrow ml-20px" href="<?= Url::to('@web/designer/recruit-list') ?>">查看我的投递</a>
                    </p>
                </div>
            </div>
            <?= $this->render('/right-simple/article') ?>
            <?= $this->render('/right-simple/recruit') ?>
        </div>
    </div>
</div>
<div style="display:none;">
    <?= Render::select('', $categories, null, ['id' => 'categories']) ?>
    <?= Render::select('', $models, null, ['id' => 'models']) ?>
    <?= Render::select('', Design::$styleSelector, null, ['id' => 'styles']) ?>
</div>

<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tableHandler.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // 名称显示
        var lists = [['.categories', '#categories'], ['.models', '#models'], ['.styles', '#styles']];
        for(var i = 0; i < lists.length; ++i) {
            tableHandler.renderCategory({ category: $(lists[i][0]), select: lists[i][1], color: false, splite: '，' });
        }
        // 投递简历
        tableHandler.requestSingle({
            button: '#delivery-button', isConfirm: true, isShadow: true,
            url: "<?= Url::to('@web/designer/recruit-applicant') ?>",
            beforePost: function(param) {
                param.data = { id: '<?= $recruit->id ?>' };
            },
            requestSuccess: function (param) {
                layer.alert(param.response.message, { icon: 6 }, function() {
                    $(param.mthis).after('<span class="flyer-status green">已投递</span>');
                    $(param.mthis).remove();
                    layer.closeAll();
                });
            }
        });
    });
</script>